package com.kexun.servlet.student;

import com.alibaba.fastjson.JSON;
import com.kexun.pojo.User;
import com.kexun.service.StuService;
import com.kexun.service.impl.StuServiceImpl;
import com.sun.org.apache.xpath.internal.objects.XString;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Map;

@WebServlet("/ServletCourse")
public class ServletCourse extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");

        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        String StuNum = user.getUserNum();


        String limitStr = request.getParameter("limit");
        String pageStr = request.getParameter("page");
        String coursename = request.getParameter("courseName");

        System.out.println(limitStr);
        System.out.println(pageStr);
        System.out.println(coursename);

        int limit = Integer.parseInt(limitStr);
        int page = Integer.parseInt(pageStr);


        StuService stu = new StuServiceImpl();
         Map<String,Object> map = stu.findCourse(StuNum,page,limit,coursename);

        String s = JSON.toJSONString(map);
        response.getWriter().print(s);


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
